package com.ocom.payconfig.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.payconfig.EntityDishesWhite;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payconfig.dao.IDaoDishesWhite;
import com.ocom.payconfig.service.DishesWhiteService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DishesWhiteServiceImpl extends ServiceImpl<IDaoDishesWhite, EntityDishesWhite> implements DishesWhiteService {



    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public boolean removeDishesWhite(Long comId, Integer dishesId, Integer merchId) {
        QueryWrapper<EntityDishesWhite> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("com_id",comId);
        queryWrapper.eq("dishes_id",dishesId);
        queryWrapper.eq("merch_id",merchId);
        return this.remove(queryWrapper);
    }

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public boolean insertDishesWhite(Long comId, EntityDishesWhite entityDishesWhite) {
        return this.save(entityDishesWhite);
    }

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public boolean removeDishesAllDownload(Long comId, Integer merchId) {
        QueryWrapper<EntityDishesWhite> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("com_id",comId);
        queryWrapper.eq("merch_id",merchId);
        return this.remove(queryWrapper);
    }

    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    @Override
    public boolean insertDishesWhites(Long comId, List<EntityDishesWhite> insertList) {
        return this.saveBatch(insertList);
    }
}
